package org.gfix.converter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.gfix.types.FixVersion;
import org.junit.Test;

public class EnumConverterTest {

	public enum PlainEnum{HELLO,WORLD};
	
	@Test
	public void testGetEnumConverter() throws Exception{
		EnumConverter<FixVersion> ec = EnumConverter.getEnumConverter(FixVersion.class);
		assertNotNull(ec);
	}
	


	@Test
	public void testConvertFromFixAnnotatedEnum()throws Exception
	{
		EnumConverter<FixVersion> ec = EnumConverter.getEnumConverter(FixVersion.class);
		assertNotNull(ec);
		FixVersion fv= (FixVersion)ec.convertFromFix("FIX.4.2");
		assertNotNull(fv);
		assertEquals(FixVersion.FIX_42, fv);
		
		fv= (FixVersion)ec.convertFromFix("FIX.BLAH");
		
		assertNull(fv);
		
	}

	@Test
	public void testConvertToFixAnnotatedEnum()throws Exception
	{
		EnumConverter<FixVersion> ec = EnumConverter.getEnumConverter(FixVersion.class);
		assertNotNull(ec);
		assertEquals("FIX.4.2", ec.convertToFix(FixVersion.FIX_42));
	}
	
	@Test
	public void testConvertFromFixPlainEnum()throws Exception
	{
		EnumConverter<PlainEnum> ec = EnumConverter.getEnumConverter(PlainEnum.class);
		assertNotNull(ec);
		PlainEnum fv= ec.convertFromFix("WORLD");
		assertNotNull(fv);
		assertEquals(PlainEnum.WORLD, fv);
		
		fv= ec.convertFromFix("FIX.BLAH");
		
		assertNull(fv);
		
	}

	@Test
	public void testConvertToFixPlainEnum()throws Exception
	{
		EnumConverter<PlainEnum> ec = EnumConverter.getEnumConverter(PlainEnum.class);
		assertNotNull(ec);
		assertEquals("HELLO", ec.convertToFix(PlainEnum.HELLO));
	}

}
